package com.unhz.taigu.service.impl;

import com.unhz.generator.dao.InsoleDictMapper;
import com.unhz.generator.enums.EnumOderStatus;
import com.unhz.generator.pojo.InsoleDict;
import com.unhz.generator.utils.IsNumeric;
import com.unhz.generator.utils.Page;
import com.unhz.generator.vo.OrderVo;
import com.unhz.taigu.service.InsoleDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: 沈佳庆
 * @Description: 中底数据信息字典
 * @Date: Created in 下午 6:26 2018/1/29 0029
 * @Modified By:
 */
@Service
public class InsoleDictServiceImpl implements InsoleDictService{

    @Autowired
    private InsoleDictMapper insoleDictMapper;

    public List<InsoleDict> selectInsoleByTradition(){
        List<InsoleDict> list = insoleDictMapper.selectInsoleByTradition();
        return list;
    }

    @Override
    public List<InsoleDict> selectInsoleByInjection() {
        return insoleDictMapper.selectInsoleByInjection();
    }

    @Override
    public List<InsoleDict> selectInsoleByResin() {
        return insoleDictMapper.selectInsoleByResin();
    }

    @Override
    public Page<InsoleDict> selectPageTradition(String pageNo, Integer pageSize, String keywords) {
        int pageNum = 1;
        boolean numok = IsNumeric.isNumeric(pageNo);
        if(numok){
            if(pageNo !=null && !"".equals(pageNo)){
                pageNum = Integer.parseInt((pageNo));  // 页数
            }
        }
        int totalRecords = insoleDictMapper.selectTotalRecordsByTradition(keywords);   //获取记录总条数
        Page page = new Page(pageNum,totalRecords);
        page.setPageSize(pageSize);  //每页显示条数
        Map<String ,Object> map = new HashMap<String,Object>();
        map.put("startIndex",page.getStartIndex());
        map.put("pageSize",page.getPageSize());
        map.put("keywords",keywords);
        //获取总记录数
        List<InsoleDict> records = insoleDictMapper.selectTradition(map);
        page.setRecords(records);
        String uri = "/insoleDicts/findAllTradition?keywords="+keywords;
        page.setUri(uri);
        return page;
    }

    @Override
    public Page<InsoleDict> selectPageInjection(String pageNo, Integer pageSize, String keywords) {
        int pageNum = 1;
        boolean numok = IsNumeric.isNumeric(pageNo);
        if(numok){
            if(pageNo !=null && !"".equals(pageNo)){
                pageNum = Integer.parseInt((pageNo));  // 页数
            }
        }
        int totalRecords = insoleDictMapper.selectTotalRecordsByInjection(keywords);   //获取记录总条数
        Page page = new Page(pageNum,totalRecords);
        page.setPageSize(pageSize);  //每页显示条数
        Map<String ,Object> map = new HashMap<String,Object>();
        map.put("startIndex",page.getStartIndex());
        map.put("pageSize",page.getPageSize());
        map.put("keywords",keywords);
        //获取总记录数
        List<InsoleDict> records = insoleDictMapper.selectInjection(map);
        page.setRecords(records);
        String uri = "/insoleDicts/findAllInjection?keywords="+keywords;
        page.setUri(uri);
        return page;
    }

    @Override
    public Page<InsoleDict> selectPageResin(String pageNo, Integer pageSize, String keywords) {
        int pageNum = 1;
        boolean numok = IsNumeric.isNumeric(pageNo);
        if(numok){
            if(pageNo !=null && !"".equals(pageNo)){
                pageNum = Integer.parseInt((pageNo));  // 页数
            }
        }
        int totalRecords = insoleDictMapper.selectTotalRecordsByResin(keywords);   //获取记录总条数
        Page page = new Page(pageNum,totalRecords);
        page.setPageSize(pageSize);  //每页显示条数
        Map<String ,Object> map = new HashMap<String,Object>();
        map.put("startIndex",page.getStartIndex());
        map.put("pageSize",page.getPageSize());
        map.put("keywords",keywords);
        //获取总记录数
        List<InsoleDict> records = insoleDictMapper.selectResin(map);
        page.setRecords(records);
        String uri = "/insoleDicts/findAllResin?keywords="+keywords;
        page.setUri(uri);
        return page;
    }

    @Override
    public InsoleDict selectInsoleDict(Integer insoleDictId) {
        return insoleDictMapper.selectInsoleDict(insoleDictId);
    }

    @Override
    public void updateInsoleDict(InsoleDict insoleDict) {
        insoleDictMapper.updateByPrimaryKeySelective(insoleDict);
    }

    @Override
    public String updateIsenable(Integer OrderId, Integer isenable, String adminName) {
        //修改用户的禁用启用状态
        InsoleDict insoleDict = new InsoleDict();
        insoleDict.setId(OrderId);
        insoleDict.setValid(isenable);
        insoleDict.setUpdateBy(adminName);
        int count = insoleDictMapper.updateByPrimaryKeySelective(insoleDict);
        if( count > 0){
            return "success";
        }
        return "failed";
    }

    @Override
    public List<InsoleDict> selectAllInsoleDict() {
        return insoleDictMapper.selectAllInsoleDict();
    }


}
